#include "pvsystem.h"
#include <QIcon>
#include <QDebug>

PVSystem::PVSystem(const QString& name, QObject* parent)
    : Component(name, parent)
{
    m_icon = QIcon(":/icons/pv.png");

    // 初始化默认预测曲线（正弦波）
    for (int i = 0; i < 96; i++) {
        // 白天有输出，晚上为0
        double hour = i * 0.25; // 转换为小时
        if (hour >= 6 && hour <= 18) {
            m_forecast.append(50.0 * sin((hour - 6) * 3.14159 / 12.0));
        } else {
            m_forecast.append(0.0);
        }
    }
}

void PVSystem::update(int timeStep, double dt) {
    Q_UNUSED(dt);
    if (timeStep < m_forecast.size()) {
        m_power = m_forecast[timeStep];
    } else {
        m_power = 0.0;
    }
}

void PVSystem::modifyParameters() {
    qDebug() << "修改光伏系统参数:" << getName();
}

void PVSystem::loadForecast(const QVector<double>& forecast) {
    m_forecast = forecast;
}
